package com.gongJiao.service.impl;

import com.gongJiao.Vo.*;
import com.gongJiao.entity.Vehicle;
import com.gongJiao.mapper.VehicleMapper;
import com.gongJiao.service.VehicleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2021-12-25
 */
@Service
public class VehicleServiceImpl extends ServiceImpl<VehicleMapper, Vehicle> implements VehicleService {

    @Autowired
    VehicleMapper vehicleMapper;

    /**
     * 查条件询所有公交信息
     * @param vehicleVo
     * @return
     */
    @Override
    public List<AdminVehicleVo> getVehicleList(VehicleVo vehicleVo) {
        return vehicleMapper.getVehicleList(vehicleVo);
    }

    /**
     * 条件查询公交总记录数
     * @param vehicleVo
     * @return
     */
    @Override
    public Integer getCount(VehicleVo vehicleVo) {
        return vehicleMapper.getCount(vehicleVo);
    }

    /**
     * 根据站点生成路线查询公交数据集合
     * @param vehicleVo
     * @return
     */
    @Override
    public List<AdminVehicleVo> getVehicleListByRoute(VehicleVo vehicleVo) {
        return vehicleMapper.getVehicleListByRoute(vehicleVo);
    }

    /**
     * 根据站点生成路线查询公交数据集合
     * @param vehicleVo
     * @return
     */
    @Override
    public Integer getCountByRoute(VehicleVo vehicleVo) {
        return vehicleMapper.getCountByRoute(vehicleVo);
    }

    /**
     * 根据id获取公交信息
     * @param id
     * @return
     */
    @Override
    public Vehicle getVehicleById(Long id) {
        return vehicleMapper.selectById(id);
    }

    /**
     * 修改公交信息
     * @param vehicle
     * @return
     */
    @Override
    public Boolean updateVehicle(Vehicle vehicle) {
        int i = vehicleMapper.updateById(vehicle);
        if (i > 0) {
            return true;
        }
        return false;
    }

    /**
     * 删除公交信息
     * @param ids
     */
    @Override
    public void deleteVehicleByIds(String ids) {
        String[] idArray = ids.split(",");
        List idList=new ArrayList<>();
        for (String id : idArray) {
            idList.add(id);
        }
        vehicleMapper.deleteBatchIds(idList);
    }

    /**
     * 判断公交名是否可用
     * @param name
     * @return
     */
    @Override
    public Vehicle getVehicleByName(String name) {
        if (name == null && "".equals(name)) {
            return null;
        }
        return vehicleMapper.getvehicleByName(name);
    }

    /**
     * 跟路线id获取使用路线的使用公交名称集合字符串
     * @param ids
     * @return
     */
    @Override
    public String getVehicleByNames(Long ids) {
        return vehicleMapper.getVehicleByNames(ids);
    }

    /**
     * 跟据分类id获取使用该分类的公交名称集合字符串
     * @param ids
     * @return
     */
    @Override
    public String getVehicleByTypeId(Long ids) {
        return vehicleMapper.getVehicleByTypeId(ids);
    }

    /**
     * 获取六条公交信息
     * @return
     */
    @Override
    public List<Vehicle> getSixVehicle() {
        return vehicleMapper.getSixVehicle();
    }

    /**
     * 前台根据id获取公交信息
     * @param id
     * @return
     */
    @Override
    public WebVehicleInfo getwebVehicleInfoById(Long id) {
        return vehicleMapper.getWebVehicleInfoById(id);
    }

    /**
     * 前台根据id获取公交站点信息
     * @param id
     * @return
     */
    @Override
    public WebVehicleSiteInfo getwebVehicleSiteInfoById(Long id) {
        return vehicleMapper.getWebVehicleSiteInfoById(id);
    }
}
